﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta "name"="viewport" content="width=device-width, initial-scale=1.0">

<title>My JSP 'sys_organize_list.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="shortcut icon" href="${ctx }/ico/favicon.ico">
<link href="${ctx }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${ctx }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<!-- jqgrid-->
<link href="${ctx }/css/plugins/jqgrid/ui.jqgrid.css?0820"
	rel="stylesheet">
<link href="${ctx }/css/animate.css" rel="stylesheet">
<link href="${ctx }/css/common.css" rel="stylesheet">
<link href="${ctx }/css/style.css?v=4.1.0" rel="stylesheet">
<!-- Sweet Alert -->
<link href="${ctx }/css/plugins/sweetalert/sweetalert.css"
	rel="stylesheet">
<!-- zTree -->
<link href="${ctx }/css/plugins/demo/demo.css" rel="stylesheet">
<link href="${ctx }/css/plugins/zTreeStyle/metro.css" rel="stylesheet">
<link href="${ctx }/css/font-awesome.css" rel="stylesheet">
</head>

<body>
	<div class="ibox-title" style="background:#f0f0f0">
		<h5>数据字典</h5>
	</div>
	<div class="row">
		<div class="ibox-content" >

			<div class="zTreeDemoBackground left" style="float:left;width:500px;">
				<ul id="treeDemo" class="ztree" ></ul>
			</div>
			<!-- <!-- start 加载成员列表  -->
			<div
				style="hidden:ture;overflow-x:hidden;margin-right: 3px;"
				id="userInfoWin"  role="dialog" aria-hidden="true">
				<iframe id="userInfoFrame" width="100%"
					frameborder="0" style="overflow:hidden;height:calc(100% - 150px)"> </iframe>
			</div>
		</div>
	</div>
	<!-- 添加部门模块窗口 -->
	<div class="modal inmodal" id="addSysDictWin" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated bounceInRight">
				<div class="modal-header">
					<button type="button" class="close closeWin" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
					</button>
					<h5 class="modal-title" style="padding:0px;color:#fff">添加数据字典</h5>
				</div>
				<div class="ibox-content">
					<form class="form-horizontal m-t" id="addSysDictFrom">
						<div class="form-group">
							<label class="col-sm-3 control-label">父节点ID：</label>
							<div class="col-sm-8">
								<input id="parent_dictid" name="parent_dictid" class="form-control"
									 type="text" readonly="true">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">字典名称：</label>
							<div class="col-sm-8">
								<input id="dictname" name="dictname" class="form-control"
									required="" aria-required="true" type="text" value=""
									placeholder="请输字典名称">
							</div>
						</div>
						<div class="form-group">
							<label id="org_id" class="col-sm-3 control-label">字典别名：</label>
							<div class="col-sm-8">
								<input id="dictalias" name="dictalias" class="form-control"
									type="text" value="" placeholder="请输字典别名">
							</div>
						</div>
						<div class="form-group">
							<label id="point_name" class="col-sm-3 control-label">接口地值：</label>
							<div class="col-sm-8">
								<input id="dictcode" name="dictcode" class="form-control"
									type="text" value="" placeholder="请输入接口值">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">字典备注：</label>
							<div class="col-sm-8">
								<textarea class="form-control" rows="3" placeholder="请输入字典备注"
									name="remark"></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">字典排序：</label>
							<div class="col-sm-8">
								<input id="sort" name="sort" class="form-control" type="number"
								required="" aria-required="true"
									placeholder="请输入排序号">
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-8 col-sm-offset-3">
								<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
								<button type="submit" class="btn btn-primary">保存</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- 编辑模块窗口Start -->
	<div class="modal inmodal" id="editDictWin" role="dialog"
		aria-hidden="true" style="padding-bottom:30px">
		<iframe id="editDictFrame" width="100%" height="100%" frameborder="0"></iframe>
	</div>
	<!-- 全局js -->
	<script src="${ctx }/js/jquery.min.js?v=2.1.4"></script>
	<script src="${ctx }/js/bootstrap.min.js?v=3.3.6"></script>
	<!-- Peity -->
	<script src="${ctx }/js/plugins/peity/jquery.peity.min.js"></script>
	<!-- jqGrid -->
	<script src="${ctx }/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
	<script src="${ctx }/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>
	<!-- jQuery Validation plugin javascript-->
	<script src="${ctx }/js/plugins/validate/jquery.validate.min.js"></script>
	<script src="${ctx }/js/plugins/validate/messages_zh.min.js"></script>
	<!-- layer javascript -->
	<script src="${ctx }/js/plugins/layer/layer.min.js"></script>
	<!-- jQuery form-->
	<script src="${ctx }/js/jquery.form.js"></script>
	<!-- 自定义js -->
	<script src="${ctx }/js/content.js?v=1.0.0"></script>
	<!-- Sweet alert -->
	<script src="${ctx }/js/plugins/sweetalert/sweetalert.min.js"></script>
	<script src="${ctx }/js/plugins/bootstrap-table/bootstrapValidator.js"></script>
	<!-- ztree plugin javascript -->
	<script src="${ctx }/js/plugins/zTree/jquery.ztree.core.min.js"></script>
	<script src="${ctx }/js/plugins/zTree/jquery.ztree.exhide.min.js"></script>
	<script src="${ctx }/js/plugins/zTree/jquery.ztree.exedit.min.js"></script>
	<script src="${ctx }/js/plugins/zTree/jquery.ztree.excheck.min.js"></script>
	<script type="text/javascript">
		var setting = {
			data : {
				simpleData : {
					enable : true,
					idKey: "id",
					pIdKey: "pId"
				}
			},
			view: {
			    expandSpeed: "slow",
				addHoverDom: addHoverDom,
				removeHoverDom: removeHoverDom,
				selectedMulti: false
			},
			callback : {
				onClick: zTreeOnClick,//点击事件
				//onRightClick: zTreeOnRightClick,//点击右键
				//onClick:   show,
				beforeRemove:beforeRemove,//点击删除时触发，用来提示用户是否确定删除
			    //onRemove:onRemove,//删除节点后触发，用户后台操作
			    beforeEditName: beforeEditName,//点击编辑时触发，用来判断该节点是否能编辑
		        //beforeRename:beforeRename,//编辑结束时触发，用来验证输入的数据是否符合要求
		        //onRename:onRename,//编辑后触发，用于操作后台
		        
			},
			edit: {
				enable: true,
				drag: {//禁止拖拽
					isCopy: false,
					isMove: false
				},
				//showRemoveBtn: showRemovBtn,
				showRemoveBtn: true,
				showRenameBtn: true
				},
			async : {
				enable : true,
				url :"${ctx}/dict/execute",
				autoParam : [ "id", "name" ]
			}
		};
		var treeObj;
		
		$(document).ready(function() {
			$.fn.zTree.init($("#treeDemo"), setting);
			setEdit();
			treeObj=$.fn.zTree.getZTreeObj("treeDemo");
			
			$.jgrid.defaults.styleUI = 'Bootstrap';
			// Examle data for jqGrid
			var searchString='';
			var detail= "123";//做限制
			
			
		});
	
		function setEdit() {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			removeTitle = "删除",
			renameTitle = "修改";
			setting.edit.showRemoveBtn =true;
			setting.edit.showRenameBtn = true;
			zTree.setting.edit.removeTitle = "删除";
			zTree.setting.edit.renameTitle = "修改";
			}
		function showRemovBtn(treeId, treeNode){
		 if(treeNode.show_switch==true){
		    return true;
		 }else{
		    return false;
		  }
		}
		function showRenameBtn(treeId, treeNode){
		 if(treeNode.show_switch==true){
		    return true;
		 }else{
		    return false;
		  }
		}
		//单击节点时查看该节点下的人员信息
		function zTreeOnClick(e, treeId, treeNode) {
			var v_dictid = treeNode.id;
	        var frameSrc = "${ctx }/dict/detailDict?dictid="+v_dictid;
			$('#userInfoFrame').attr("src", frameSrc);
			$('#userInfoWin').show();
		};
		
		//添加部门
		var v_treeNode;
		function addHoverDom(treeId, treeNode) {
			v_treeNode=treeNode;
			var sObj = $("#" + treeNode.tId + "_span");
			
			if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
			if (treeNode.editNameFlag || $("#diyDownloadBtn_"+treeNode.id).length>0) return;
			if (treeNode.editNameFlag || $("#diyUploadBtn_"+treeNode.tId).length>0) return;
			var addStr =
			"<span class='button add' id='addBtn_" + treeNode.tId + "' title='添加' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			$("#addBtn_"+treeNode.tId).click(function(){
				$("#addSysDict").attr("disabled", false);
				$("#parent_dictid").val(treeNode.id);
				$("#parent_name").val(treeNode.name);
				$('#addSysDictWin').modal('show');
			});
		};
		
    	//添加字典数据
		$("#addSysDictFrom").submit(function(){
			$("#addSysDict").attr("disabled", true);
			$.ajax({
				async : false, //同步
		    	type: "post",
		    	url: "${ctx }/dict/addDict",
		    	dataType:"json",
		     	data: $('#addSysDictFrom').serialize(),
		     	success: function(data) {
		      		if(data.errcode==1)
		      		{
		      			layer.alert(data.errmsg,{icon: 2}, function(index){
		      			   $("#addSysDictFrom :input").not(":button, :submit, :hidden").val("").remove("selected");
							$('#addSysDictWin').modal('hide');//关闭add窗口
							//关闭提示框
							layer.close(index);
		      			});
		      		}else
		      		{
		      			
		      			layer.alert(data.errmsg,{icon: 1}, function(index){
		      				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		      				console.log(data);
		      				zTree.addNodes(v_treeNode,{id:data.data.dictid, pId:data.data.parent_dictid, name:data.data.dictname});
							$("#addSysDictFrom :input").not(":button, :submit, :hidden").val("").remove("selected");
							$('#addSysDictWin').modal('hide');//关闭add窗口
							//关闭提示框
							layer.close(index);
						});
		      		}
		      	},
		      	error: function() {		      		
		      		layer.alert('添加数据字典异常！',{icon: 2});
        		}
        	});
       		return false;
		});
		
	//编辑字典数据
	 function beforeEditName(treeId, treeNode) {
		var fromUrl = "${ctx }/dict/editDict?dictid="+treeNode.id;
		$("#editDictFrame").attr("src", fromUrl);
		$('#editDictWin').modal('show');
		return false;
	} 
	
	function editDictWinClose(data){
		if(data=='0'){
			treeObj.reAsyncChildNodes(null, "refresh");//重新加载treeObj
		}
		//关闭edit窗口
		$("#editDictFrame").attr("src", "");
		document.getElementById("editDictFrame").innerText = "";
		$('#editDictWin').modal('hide');
   }
	
			   /** 
     * 刷新当前选择节点的父节点 
     */  
    function refreshParentNode() {  
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),  
        type = "refresh",  
        silent = false,  
        nodes = zTree.getSelectedNodes();  
        /*根据 zTree 的唯一标识 tId 快速获取节点 JSON 数据对象*/  
        var parentNode = zTree.getNodeByTId(nodes[0].parent_org_id);  
        /*选中指定节点*/  
        zTree.selectNode(parentNode);  
        zTree.reAsyncChildNodes(parentNode, type, silent);  
    } 
		//鼠标移开后隐藏添加修改删除
		function removeHoverDom(treeId, treeNode) {
			$("#addBtn_"+treeNode.tId).unbind().remove();
			$("#diyDownloadBtn_"+treeNode.id).unbind().remove();
			$("#diyUploadBtn_"+treeNode.id).unbind().remove();
		};
		
		//点击删除时触发，用来提示用户是否确定删除
		function beforeRemove(treeId,treeNode){
		   	layer.confirm('您确定要删除该节点吗,操作后数据不可恢复?',{icon : 3,title : '提示'},function() {
				 var id =treeNode.id;
			    $.ajax({
    			async: false,
    			type: "post",
    			url: "${ctx }/dict/delDict", 
    			data: "dictid="+id,
    			success: function(data) {
    			    if(data.errcode==0){
						layer.alert(data.errmsg,{icon: 1});
						treeObj.removeNode(treeNode);
					}else{
						layer.alert(data.errmsg,{icon: 2});
					}
    			        
		    	},
		      	error: function() {
        		}
			});	
			},function() {
				console.log(false);
				layer.close(layer.index); //再执行关闭  
			});
			return false;
		}
        
	</script>
</body>
</html>
